
import { createSlice } from '@reduxjs/toolkit'

export  const  numReducer = createSlice({
    name:"numInfo",
    initialState:{num:10},
    reducers:{//
        addNum:(state,action)=>{
            state.num  = state.num+action.payload;
        },
        reduceNum:(state,action)=>{
            state.num  = state.num-action.payload;
        }
    }

});
export const  {addNum,reduceNum}  = numReducer.actions; //从所有方法里面 找出addNum
//方法
export  default  numReducer.reducer;//纯函数

// import typeInfo from "../action";
// function  numReducer(state={num:10},action:any){
    
//     switch(action.type){
//         case  typeInfo.ADDNUM:
//             return  {num:state.num+action.payload}
//         default:
//             return  state;
//     }
// }

// let numRuducer = {
//     actions:{
//         addNum:(payload:any)=>{
//             return {
//                 type:typeInfo.ADDNUM,
//                 payload,
//             }
//         }
//     }
  
// }
// export  const {addNum} = numReducer.actions
// export  const  addNum = (payload:any)=>{
//     return {
//         type:typeInfo.ADDNUM,
//         payload,
//     }
// }

// export  default  numReducer;